package com.demo.springboot.controller;

import com.demo.springboot.dao.UserDao;
import com.demo.springboot.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author tianqinglong
 * @Date 19:21 2022/7/14
 * @Version 1.0
 **/
@Controller
public class UserController {
    @Autowired
    private UserDao userDao;
    @RequestMapping("login")
    @ResponseBody
    public String login( User user){
        System.out.println(user);
        ArrayList<User> list = userDao.getList();
        for (int i = 0; i < list.size(); i++) {
            String userName = user.getUserName();
            String passWord = user.getPassWord();
            if(userName.equals(list.get(i).getUserName())&&passWord.equals(list.get(i).getPassWord())){
                return "登录成功";
            }
        }
        return "登录失败";
    }
}
